package com.homework;

import java.io.File;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/4/2 17:11
 * @description
 */
public class T1 {
    static int dot = 0;
    static int java = 0;
    static int txt = 0;

    public static void main(String[] args) {
//        File dir = new File("D:\\file\\test");
        Scanner input = new Scanner(System.in);
        System.out.println("请输入文件夹路径：");
        String Path = input.nextLine();
        File dir = new File(Path);
        typeCount(dir);
        HashMap hm = new HashMap();
        hm.put("docx类型的文件的个数 ",dot);
        hm.put("java的类型的文件的个数 ",java);
        hm.put("txt的类型的文件的个数 ",txt);

        Set set = hm.entrySet();
        for (Object o : set) {
            System.out.println(o);
        }
        System.out.println("=======================");
        Set set1 = hm.keySet();
        for (Object o : set1) {
            Object o1 = hm.get(o);
            System.out.print(o);
            System.out.println(o1);
        }


    }
    public static void typeCount(File dir) {
        File[] files = dir.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                typeCount(file);
            }else {
                String fileName = file.getName();
                String type = fileName.substring(fileName.indexOf('.')+1);
                switch (type){
                    case "docx":
                        dot++;
                        break;
                    case "java":
                        java++;
                        break;
                    case "txt":
                        txt++;
                        break;
                }
            }
        }
    }
}
